// pages/mine/bbs/fans/fans.js
import { HTTP } from '../../../../utils/http.js'
let ajax = new HTTP()
const app = getApp()

Page({
    data: {
        fansArr: [],
        tomemberid: ""
    },
    onShow(options) {
        let memberid = wx.getStorageSync("memberid")
        //获取我的粉丝
        this._getMyfans(memberid)
    },
    gotoOther(event) {
        let nmemberid = event.currentTarget.dataset.memberid
        wx.navigateTo({
            url: '/pages/community/detail/other/other?nmemberid=' + nmemberid,
        })
    },
    // 关注
    onGuanZhuTap(event) {
        let tomemberid = event.currentTarget.dataset.memberid
        ajax.request({
            url: "memfavorite",
            method: "POST",
            data: {
                memberid: app.globalData.memberid,
                tomemberid: tomemberid
            },
            success: (res) => {
                if (res.rescode === "0000") {
                    for (let i = 0; i < this.data.fansArr.length; i++) {
                        if (this.data.fansArr[i].memberid === tomemberid) {
                            this.data.fansArr[i].hasguanzhu = 1
                        }
                    }
                    this.setData({
                        fansArr: this.data.fansArr
                    })
                    wx.showToast({
                        title: '关注成功',
                    })
                }
            }
        })
    },
    _getMyfans(nmemberid) {
        ajax.request({
            method: "GET",
            url: "mycenter",
            data: {
                actname: 'myfans',
                memberid: nmemberid,
                p: 0
            },
            success: (res) => {
                if (res.rescode == "0000") {
                    this.setData({
                        fansArr: res.data
                    })
                }
            }
        })
    }
})